<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sub_accounts', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('create_admin_id')->nullable()->comment('创建人id');
            $table->unsignedInteger('update_admin_id')->nullable()->comment('更新人id');
            $table->unsignedInteger('shop_id')->comment('所属店铺id');
            $table->unsignedInteger('template_id')->comment('自定义登记字段模板id');
            $table->string('sub_account')->comment('子账号名称');
            $table->unsignedInteger('source_id')->nullable()->comment('来源id');
            $table->string('account_code')->nullable()->comment('子账号密码');
            $table->char('verify_phone',20)->nullable()->comment('验证手机');
            $table->unsignedInteger('consult_quantity')->nullable()->comment('目前咨询量');
            $table->dateTime('try_time_start')->nullable()->comment('试上号时间起');
            $table->dateTime('try_time_end')->nullable()->comment('试上号时间止');
            $table->dateTime('service_time_start')->nullable()->comment('服务开始时间');
            $table->dateTime('service_time_end')->nullable()->comment('服务结束时间');
            $table->string('boss_demands')->nullable()->comment('掌柜特殊要求');
            $table->unsignedInteger('total_complain_quantity')->default(0)->comment('本店客诉总数');
            $table->unsignedInteger('forget_login_quantity')->default(0)->comment('漏上号次数');
            $table->unsignedInteger('forget_record_quantity')->default(0)->comment('漏登记数据次数');
            $table->tinyInteger('status')->default(1)->comment('默认1合作中，0停用');
            $table->tinyInteger('multi_change_status')->default(0)->comment('是否多次变更，默认0没有，1有');
            $table->dateTime('assign_staff_time')->nullable()->comment('分配客服时间');
            $table->mediumInteger('assign_staff_times')->default(0)->comment('分配客服次数');
            $table->unsignedInteger('department1_id')->nullable()->comment('所属一级部门（跟店铺走）');
            $table->unsignedInteger('department2_id')->nullable()->comment('所属二级部门（跟店铺走）');
            $table->unsignedInteger('department3_id')->nullable()->comment('所属三级部门（跟客服走）');
            $table->unsignedInteger('department_id')->nullable()->comment('最后一级部门的id');

            $table->decimal('sub_amount',10,1)->nullable()->comment('子账号金额');
            $table->text('data_screen_shots')->nullable()->comment('子账号数据截图');
            $table->dateTime('resume_at')->nullable()->comment('恢复时间');
            $table->dateTime('breakup_time')->nullable()->comment('停止合作时间');

            $table->timestamps();
            $table->softDeletes();
        });

        \DB::statement("ALTER TABLE `sub_accounts` comment '子账号表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sub_accounts');
    }
};
